function PyResult(){
	this.form=this.InitForm();
	this.table=this.InitTableByBt();
	this.InitOrg();
}


PyResult.prototype.InitOrg = function() {
	var comboboxm=$("#orgid").ligerComboBox({
		valueField : 'orgid',
		textField : 'orgname',
		selectBoxWidth : 250,
		selectBoxHeight:250,
		treeLeafOnly:false,
		valueFieldID:"hid",
		tree: {url : '../common/get_org_list?orgtype=0',
			checkbox: false, 
			nodeWidth:150,
			ajaxType: 'get', 
			idFieldName: 'orgid',
			textFieldName:"orgname",
			idField:"orgid",
        	parentIDField:"orgparentid"
		},
		onSelected : function(orgid, orgname) {// id为空值，name为选择的值
			$("#hidszdw").val(orgid);
			vPyResult.searchtable()
		},
		width : 250
	});
	return comboboxm;
}

PyResult.prototype.InitForm=function(){
	var form;
    $("#year").val($("#hidyear").val());
	layui.use('form', function(){
       form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
       form.on('select(year)', function (data) { 

    	   vPyResult.searchtable();
       });
       
       form.on('select(zzpdjg)', function (data) { 
  
    	   vPyResult.searchtable();
       });
       
       form.on('select(dymzpyjg)', function (data) { 
 
    	   vPyResult.searchtable();
       });
       
       form.on('select(szdw)', function (data) { 
    	    
    	   vPyResult.searchtable();
       });
       
	   form.render();
	});  
	return form;
}

PyResult.prototype.InitTableByBt=function (){

	var table;
	var _this=this;
	layui.use('table', function() {
	    table = layui.table;
	    table.init('uatmzpdsummarylist', {
			height : $(window).height() - 100
			,url : 'get_summary_list' // 数据接口
			,page : true // 开启分页
			,limit : 40
			,limits:[20,40,80,100]
			,id: 'uatmzpdsummary'
			,method:"post"
				,request:{
					type:'post'
				}
				,where:{
					year: $("#year").val(),
					zzpdjg:$("#zzpdjg").val(),
					dymzpyjg:$("#dymzpyjg").val(),
					szdw:$("#hidszdw").val(),
			     	username:$('#username').val()
					}
			    ,done: function(res, page, count){
			    	
			    	var dataarr=res.data;
			    	$("[data-field='begintime']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			var begin=(new Date(text)).format("yyyy-MM-dd");
			    			$(this).text(begin);
			    		}
	               })  
	               $("[data-field='endtime']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			var begin=(new Date(text)).format("yyyy-MM-dd");
			    			$(this).text(begin);
			    		}
	              })
	              $("[data-field='year']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			if(text=="0"){
			    				$(this).text($("#year").val());
			    			}
			    			
			    		}
	              }) 
	              
	              $("[data-field='yzhdf']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			if(text=="0"){
			    				$(this).text("");
			    			}
			    			
			    		}
	              }) 
	              
	              $("[data-field='ezhdf']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			if(text=="0"){
			    				$(this).text("");
			    			}
			    			
			    		}
	              }) 
	              
	              $("[data-field='szhdf']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			if(text=="0"){
			    				$(this).text("");
			    			}
			    			
			    		}
	              }) 
	              
	              $("[data-field='sizhdf']").children().each(function(index){ 
			    		if(index>0){
			    			var text=$(this).text();
			    			if(text=="0"){
			    				$(this).text("");
			    			}
			    			
			    		}
	              }) 
	               
			    }
				
				
		  });
	    
	    
	    //监听工具条
	    table.on('tool(uatmzpdsummarylist)', function(obj){
	    	
	      var data = obj.data;
	      if(obj.event === 'detail'){
	        layer.msg('ID：'+ data.id + ' 的查看操作');
	      } else if(obj.event === 'del'){
	    	  
	        top.mylayui.confirm('确定要删除吗？',{icon: 0}, function(index,dd){
	        	 top.mylayui.close(index);
	        	 vUser.deleteentity(data.userid);
	        });
	      } else if(obj.event === 'wjsm'){
	    	  vPyResult.openadd(obj.data.userid,$("#year").val(),0);
	      }
	      else if(obj.event === 'btnsb'){
	    	  top.mylayui.confirm('确定要归档吗？',{icon: 0}, function(){
	    		  vPyResult.updatemzpdsummarystatus(data.mzpdsummaryid);
	    	  });
	    	 
		  }
	    });
	    
	    
	})
	
	return table;
	
	

}


PyResult.prototype.openadd=function(userid,year,quarter){

	top.mylayui.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: 0.5,
        area: ['700px', '250px'],
        content: 'common/user_vtdp?userid='+userid+"&year="+year+"&quarter="+quarter
      });
//	$("#wjiframe").attr("src", '../common/user_vtdp?userid='+userid);
//	top.mylayui.open({
//		  type: 1,
//		  title: false,
//		  closeBtn: 0,
//		  shadeClose: true,
//		  skin: 'yourclass',
//		  area: ['500px', '300px'],
//		  content: $("#wjcontent")
//		});
	

}

PyResult.prototype.searchtable=function(){
	this.table.reload('uatmzpdsummary', { 
		  page: {
	        curr: 1 //重新从第 1 页开始
	      }
	    ,where: {  
	    	year: $("#year").val(),
			zzpdjg:$("#zzpdjg").val(),
			dymzpyjg:$("#dymzpyjg").val(),
			szdw:$("#hidszdw").val(),
			username:$('#username').val()
	    }  
	}); 
}




PyResult.prototype.exportexcel=function(){
	
	top.ShowZheZhao();
	$.ajax({
		type:"POST",
		url:"export_excel_all",
		data:{
			year: $("#year").val(),
			zzpdjg:$("#zzpdjg").val(),
			dymzpyjg:$("#dymzpyjg").val(),
			szdw:$("#hidszdw").val(),
            username:$('#username').val()
			},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				//top.mylayui.msg(data.msg, {icon: 1});
				//alert(data.msg);
				window.open(data.msg,'_self');
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
			top.ShowZheZhao();
			
		},
		complete:function(XHR){
			top.mylayui.closeAll('loading');
		},
		error:function(){
			
		}
	});
}


PyResult.prototype.updatemzpdsummarystatus=function(mzpdsummaryid){
	$.ajax({
		type:"POST",
		url:"update_mzpdsummarystatus",
		data:{mzpdsummaryid:mzpdsummaryid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				document.location.reload();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
}


PyResult.prototype.updatemzpdsummarystatus=function(mzpdsummaryid){
	$.ajax({
		type:"POST",
		url:"update_mzpdsummarystatus",
		data:{mzpdsummaryid:mzpdsummaryid},
		beforeSend:function(XHR){
			
		},
		success:function(data){
			data=eval('('+data+')');
			if(data.result>0){
				top.mylayui.msg(data.msg, {icon: 1});
				document.location.reload();
			}
			else{
				top.mylayui.msg(data.msg, {icon: 0});
			}
		},
		complete:function(XHR){
			
		},
		error:function(){
			
		}
	});
}

var vPyResult=null;
$(function(){
	vPyResult=new PyResult();
})